`
https://leetcode.cn/problems/number-of-substrings-containing-all-three-characters/
`

/**
 * @param {string} s
 * @return {number}
 */
var numberOfSubstrings = function (s) {
  const n = s.length
  let res = 0
  const cnt = new Array(3).fill(0)
  let left = 0, right = 0

  while (right < n) {
    const c = s[right++]
    cnt[c.charCodeAt(0) - 'a'.charCodeAt(0)]++

    while (cnt[0] > 0 && cnt[1] > 0 && cnt[2] > 0) {
      const d = s[left++]
      cnt[d.charCodeAt(0) - 'a'.charCodeAt(0)]--
    }

    // 窗口内的子串加上 left 之前的所有字符拼接成的子串都是答案，有 left 个
    res += left
  }

  return res
};